package com.fjsh.web;

import com.fjsh.mq.provider.MqProvider;
import com.fjsh.service.ActivitiRemoteService;
import com.fjsh.utils.RedisUtil;
import com.fjsh.vo.ActCustomVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.concurrent.TimeUnit;

@RestController
public class SystemController {

    @Autowired
    private ActivitiRemoteService activitiRemoteService;

    @Autowired
    private MqProvider mqProvider;

    @Autowired
    private RedisUtil redisUtil;

    @GetMapping(value = "list")
    public List<ActCustomVO> list() {

        List<ActCustomVO> actCustomList = activitiRemoteService.getActCustomList();

        return actCustomList;
    }

    @ResponseBody
    @GetMapping("/rabbit")
    public String testRabbit(){

        boolean cccc = redisUtil.exist("cccc");
        if (cccc){
            System.out.println("设置进去了");
        }else {
            redisUtil.setCacheObject("cccc",111);
            redisUtil.expire("cccc",120, TimeUnit.SECONDS);
        }

        System.out.println("此处断电，测试是否还能发送消息出去");

        mqProvider.sendDeadMsg("消息队列更新数据库");
        return "success";
    }

}
